<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="使用express创建自己第一个nodejs程序二"><meta name="keywords" content="Node.js"><meta name="author" content="kyren"><meta name="copyright" content="kyren"><title>使用express创建自己第一个nodejs程序二 | Kyren's Blog</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.9.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.9.0"><meta name="format-detection" content="telephone=no"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://hm.baidu.com"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cf87fcdbd9ab7cf93d894f7c219ae78f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();</script><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script src="https://v1.hitokoto.cn/?encode=js&amp;charset=utf-8&amp;select=.footer_custom_text" defer></script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  hexoVersion: '6.2.0'
} </script><meta name="generator" content="Hexo 6.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar" data-display="true"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%89%E3%80%81mongoose%E5%AE%89%E8%A3%85%E4%B8%8E%E4%BD%BF%E7%94%A8"><span class="toc-number">1.</span> <span class="toc-text">三、mongoose安装与使用</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%89%E8%A3%85socket-io"><span class="toc-number"></span> <span class="toc-text">安装socket.io</span></a></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://avatars.githubusercontent.com/u/5827823?v=4"></div><div class="author-info__name text-center">kyren</div><div class="author-info__description text-center">huluo的技术博客</div><div class="follow-button"><a target="_blank" rel="noopener" href="https://github.com/huluo666">Follow Me</a></div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">239</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">41</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">29</span></a></div><hr><div class="author-info-links"><div class="author-info-links__title text-center">Links</div><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:9090/">Jira</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:8090/">Confluence</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://bloc.leniugame.com/">Leniu</a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">Kyren's Blog</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus">   <a class="site-page" href="/">主页</a><a class="site-page" href="/essay">随笔</a><a class="site-page" href="/archives">归档</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a><a class="site-page" href="/about">关于</a></span><span class="pull-right"><a class="site-page social-icon search"><i class="fa fa-search"></i><span> 搜索</span></a></span></div><div id="post-info"><div id="post-title">使用express创建自己第一个nodejs程序二</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2017-02-10</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/Node-js/">Node.js</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><p>一、添加和安装依赖</p>
<p><code>package.json</code>这个基本的JSON文件描述了我们的程序以及依赖，比如添加mongodb库，内容如下</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">&quot;dependencies&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;body-parser&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~1.16.0&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;cookie-parser&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~1.4.3&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;debug&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~2.6.0&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;express&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~4.14.1&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;jade&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~1.11.0&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;morgan&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~1.7.0&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;serve-favicon&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~2.3.2&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;mongodb&quot;</span><span class="punctuation">:</span> <span class="string">&quot;~2.2.31&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<p>Note：如何使用npm 查询库信息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm view mongodb version  //mongodb库最新版本</span><br><span class="line">npm view mongodb versions //mongodb库所有版本号</span><br><span class="line">npm info mongodb		  //mongodb库详细信息</span><br></pre></td></tr></table></figure>



<p>二、Mongodb创建数据库并读取数据</p>
<p>下载地址：<a target="_blank" rel="noopener" href="http://www.mongodb.org/downloads">http://www.mongodb.org/downloads</a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">brew install mongodb</span><br><span class="line">mongod -version //验证是否安装了MongoDB</span><br></pre></td></tr></table></figure>



<p>使用robomongo连接数据库</p>
<p>下载：<a target="_blank" rel="noopener" href="https://robomongo.org/download">https://robomongo.org/download</a></p>
<p>打开robomongo，创建<code>localhost:27017</code>连接并connect即可</p>
<p><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/99a92e077660">Node.js开发笔记-4:MAC安装 mongodb 以及可视化工具</a></p>
<p>加入数据库链接依赖，monk和mongoose都可以，具体看个人喜好，我选择了mongoose来操作数据，因为对数据库的一些基本操作mongoose也不是很复杂，以后深入学习也有一定的基础。</p>
<p><a target="_blank" rel="noopener" href="https://codeday.me/bug/20170727/47313.html">https://codeday.me/bug/20170727/47313.html</a></p>
<p>monk轻量，简单。</p>
<p>mongoose定位在orm,相对复杂，功能更强。初学者建议使用monk，熟悉后可再用mongoose。</p>
<h5 id="三、mongoose安装与使用"><a href="#三、mongoose安装与使用" class="headerlink" title="三、mongoose安装与使用"></a>三、mongoose安装与使用</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install mongoose</span><br><span class="line">//建议app的依赖程序放在package.json包里，然后执行npm install安装</span><br></pre></td></tr></table></figure>

<p>1、创建一个db.js文件来连接数据库&#96;</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*引入mongoose模块*/</span></span><br><span class="line"><span class="keyword">var</span> mongoose = <span class="built_in">require</span>(<span class="string">&#x27;mongoose&#x27;</span>),</span><br><span class="line"><span class="variable constant_">DB_URL</span> = <span class="string">&#x27;mongodb://localhost:27017/mongoosesample&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 连接</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">//mongoose.connection.openUri(&#x27;mongodb://localhost/test&#x27;)</span></span><br><span class="line">mongoose.<span class="property">connection</span>.<span class="title function_">openUri</span>(<span class="variable constant_">DB_URL</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * 连接成功</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">mongoose.<span class="property">connection</span>.<span class="title function_">on</span>(<span class="string">&#x27;connected&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Mongoose connection open to &#x27;</span> + <span class="variable constant_">DB_URL</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 连接异常</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">mongoose.<span class="property">connection</span>.<span class="title function_">on</span>(<span class="string">&#x27;error&#x27;</span>,<span class="keyword">function</span> (<span class="params">err</span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Mongoose connection error: &#x27;</span> + err);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 连接断开</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">mongoose.<span class="property">connection</span>.<span class="title function_">on</span>(<span class="string">&#x27;disconnected&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Mongoose connection disconnected&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//导出mongoose对象　</span></span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span> = mongoose;</span><br></pre></td></tr></table></figure>

<p>更多监听事件 <a target="_blank" rel="noopener" href="http://mongoosejs.com/docs/api.html#connection_Connection">http://mongoosejs.com/docs/api.html#connection_Connection</a></p>
<p>验证是否连接成功</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">node db.js</span><br></pre></td></tr></table></figure>

<p>输出<code>Mongoose connection open to mongodb://localhost:27017/mongoosesample</code>表示成功</p>
<p>2、创建一个含Schema的模型，命名为user.js</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">/**用户信息 */</span><br><span class="line">var mongoose = require(&#x27;./db.js&#x27;)</span><br><span class="line"></span><br><span class="line">//1、定义一个Schema，指定字段名和类型</span><br><span class="line">var UserSchema = new mongoose.Schema(&#123;</span><br><span class="line">  //用户账号-定义一个属性name，类型为String,required必须</span><br><span class="line">   username: &#123;</span><br><span class="line">      type: String,</span><br><span class="line">      required: true</span><br><span class="line">    &#125;,</span><br><span class="line">    userpwd: &#123; // 密码</span><br><span class="line">      type: String,</span><br><span class="line">      required: true</span><br><span class="line">  &#125;,</span><br><span class="line">	logindate : &#123; type: Date&#125;              //最近登录时间</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">//2、将该Schema发布为Model</span><br><span class="line">var userModel = mongoose.model(&#x27;User&#x27;,UserSchema);</span><br><span class="line"></span><br><span class="line">// 暴露接口,导出模型提供外部js文件引用</span><br><span class="line">module.exports = userModel;</span><br></pre></td></tr></table></figure>

<p>参考：<a target="_blank" rel="noopener" href="https://cnodejs.org/topic/504b4924e2b84515770103dd">Mongoose学习参考文档——基础篇</a></p>
<p>常用数据库操作</p>
<p>创建一个test.js文件做一些常用操作演示</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">// 1、引入`user`</span><br><span class="line">var User = require(&quot;./user.js&quot;);</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 插入</span><br><span class="line"> */</span><br><span class="line">function insert() &#123;</span><br><span class="line"></span><br><span class="line">    var user = new User(&#123;</span><br><span class="line">        username : &#x27;Tracy McGrady&#x27;,                 //用户账号</span><br><span class="line">        userpwd: &#x27;abcd&#x27;,                            //密码</span><br><span class="line">        userage: 37,                                //年龄</span><br><span class="line">        logindate : new Date()                      //最近登录时间</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    user.save(function (err, res) &#123;</span><br><span class="line"></span><br><span class="line">        if (err) &#123;</span><br><span class="line">            console.log(&quot;Error:&quot; + err);</span><br><span class="line">        &#125;</span><br><span class="line">        else &#123;</span><br><span class="line">            console.log(&quot;Res:&quot; + res);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">insert();</span><br></pre></td></tr></table></figure>



<p>其它操作</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">function update()&#123;</span><br><span class="line">    var wherestr = &#123;&#x27;username&#x27; : &#x27;Tracy McGrady&#x27;&#125;;</span><br><span class="line">    var updatestr = &#123;&#x27;userpwd&#x27;: &#x27;zzzz&#x27;&#125;;</span><br><span class="line"></span><br><span class="line">    User.update(wherestr, updatestr, function(err, res)&#123;</span><br><span class="line">        if (err) &#123;</span><br><span class="line">            console.log(&quot;Error:&quot; + err);</span><br><span class="line">        &#125;</span><br><span class="line">        else &#123;</span><br><span class="line">            console.log(&quot;Res:&quot; + res);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">function findByIdAndUpdate()&#123;</span><br><span class="line">    var id = &#x27;56f2558b2dd74855a345edb2&#x27;;</span><br><span class="line">    var updatestr = &#123;&#x27;userpwd&#x27;: &#x27;abcd&#x27;&#125;;</span><br><span class="line"></span><br><span class="line">    User.findByIdAndUpdate(id, updatestr, function(err, res)&#123;</span><br><span class="line">        if (err) &#123;</span><br><span class="line">            console.log(&quot;Error:&quot; + err);</span><br><span class="line">        &#125;</span><br><span class="line">        else &#123;</span><br><span class="line">            console.log(&quot;Res:&quot; + res);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">function del()&#123;</span><br><span class="line">    var wherestr = &#123;&#x27;username&#x27; : &#x27;Tracy McGrady&#x27;&#125;;</span><br><span class="line"></span><br><span class="line">    User.remove(wherestr, function(err, res)&#123;</span><br><span class="line">        if (err) &#123;</span><br><span class="line">            console.log(&quot;Error:&quot; + err);</span><br><span class="line">        &#125;</span><br><span class="line">        else &#123;</span><br><span class="line">            console.log(&quot;Res:&quot; + res);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//update(); 更新</span><br><span class="line">//findByIdAndUpdate(); 根据_id更新</span><br><span class="line">//del(); 删除</span><br></pre></td></tr></table></figure>

<p>基本流程</p>
<ul>
<li>1、引入数据库连接，保证mongodb已经连接成功</li>
<li>2、引入模型（model）定义文件，即文档（表）结构定义</li>
<li>3、实例化UserModel，创建user实体</li>
<li>4、最后通过user实体对数据库进行操作，完成用户注册功能。</li>
</ul>
<p><a target="_blank" rel="noopener" href="http://www.cnblogs.com/zhongweiv/p/mongoose.html">http://www.cnblogs.com/zhongweiv/p/mongoose.html</a></p>
<p><a target="_blank" rel="noopener" href="https://i5ting.github.io/wechat-dev-with-nodejs/db/mongoose.html">https://i5ting.github.io/wechat-dev-with-nodejs/db/mongoose.html</a></p>
<p><strong>nodejs建立socket.io服务</strong></p>
<p>通过nodejs的http模块就可以方便的搭建websocket服务器环境，例如下面的代码：</p>
<h4 id="安装socket-io"><a href="#安装socket-io" class="headerlink" title="安装socket.io"></a>安装socket.io</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install socket.io</span><br></pre></td></tr></table></figure>

<p>官方示例<a target="_blank" rel="noopener" href="https://socket.io/docs/server-api/">https://socket.io/docs/server-api/</a></p>
<p>socket.io+express多房间聊天应用<br><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/40d8bc17529f">http://www.jianshu.com/p/40d8bc17529f</a><br><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/4ea6fc68f5f8">利用socket.io+nodejs打造简单聊天室</a><br><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/6966f12284b5">第十二天 长连接(net和socket.io)</a><br><a target="_blank" rel="noopener" href="http://js8.in/2011/09/29/%E5%9C%A8express%E5%92%8Csocket-io%E4%B8%AD%E4%BD%BF%E7%94%A8session/">在Express和Socket.IO中使用session</a><br><a target="_blank" rel="noopener" href="http://www.moye.me/2015/01/02/node_socket-io/">基于Socket.IO 的私聊</a><br><a target="_blank" rel="noopener" href="https://github.com/fengli12321/Socket.io-FLSocketIM-iOS">https://github.com/fengli12321/Socket.io-FLSocketIM-iOS</a><br><a target="_blank" rel="noopener" href="https://github.com/HOWIE-CH/-You-guess-I-painted-_socket">https://github.com/HOWIE-CH/-You-guess-I-painted-_socket</a><br>SRSocket<br><a target="_blank" rel="noopener" href="https://github.com/TheBloodElf/SocketIOChatDemo">https://github.com/TheBloodElf/SocketIOChatDemo</a><br><a target="_blank" rel="noopener" href="https://github.com/jingtao910429/PomeloMessageCenterSocketIO">https://github.com/jingtao910429/PomeloMessageCenterSocketIO</a><br><a target="_blank" rel="noopener" href="https://github.com/full-of-fire/Socket.IO_ChatDemo">https://github.com/full-of-fire/Socket.IO_ChatDemo</a><br><a target="_blank" rel="noopener" href="https://github.com/saturngod/Socket.io-with-iOS">https://github.com/saturngod/Socket.io-with-iOS</a></p>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">kyren</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huluo666.gitee.io/2017/02/10/使用express创建自己第一个nodejs程序二/">http://huluo666.gitee.io/2017/02/10/使用express创建自己第一个nodejs程序二/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huluo666.gitee.io">Kyren's Blog</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Node-js/">Node.js</a></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2017/02/10/%E4%BD%BF%E7%94%A8express%E5%88%9B%E5%BB%BA%E8%87%AA%E5%B7%B1%E7%AC%AC%E4%B8%80%E4%B8%AAnodejs%E7%A8%8B%E5%BA%8F/"><i class="fa fa-chevron-left">  </i><span>使用express创建自己第一个nodejs程序</span></a></div><div class="next-post pull-right"><a href="/2017/02/07/%E6%9E%81%E5%AE%A2%E5%AF%BC%E8%88%AA/"><span>极客导航</span><i class="fa fa-chevron-right"></i></a></div></nav></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2022 By kyren</div><div class="framework-info"><span>驱动 - </span><a target="_blank" rel="noopener" href="http://hexo.io"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a target="_blank" rel="noopener" href="https://github.com/Molunerfinn/hexo-theme-melody"><span>Melody</span></a></div><div class="footer_custom_text">hitokoto</div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv"><i class="fa fa-file"></i><span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/lib/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.9.0"></script><script src="/js/fancybox.js?version=1.9.0"></script><script src="/js/sidebar.js?version=1.9.0"></script><script src="/js/copy.js?version=1.9.0"></script><script src="/js/fireworks.js?version=1.9.0"></script><script src="/js/transition.js?version=1.9.0"></script><script src="/js/scroll.js?version=1.9.0"></script><script src="/js/head.js?version=1.9.0"></script><script src="/js/search/local-search.js"></script><script>if(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
  $('#top-container').addClass('is-mobile')
}</script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html>